﻿using System;
using System.Windows;
using System.Windows.Controls;
using DataStore.Domain;
using DataStore.Repositories;
using Infrastructure.ViewModels;

namespace UI.Controls
{
    /// <summary>
    /// Interaction logic for AddLink.xaml
    /// </summary>
    public partial class AddLink : UserControl
    {
        public event EventHandler<LinkSavedEventArgs> LinkSaved;


        public void OnLinkSaved(object sender, LinkSavedEventArgs e)
        {
            if(LinkSaved != null)
            {
                LinkSaved(sender, e);
            }
        }


        LinkViewModel _link;

         

        public AddLink()
        {
            InitializeComponent();
            _link = new LinkViewModel(new DataStore.Domain.Link());
            DataContext = _link;
        }

        private void AddCancel_AddClicked(object sender, RoutedEventArgs e)
        {
            //_link.Save();
            OnLinkSaved(this, new LinkSavedEventArgs(_link));

            _link = new LinkViewModel(new DataStore.Domain.Link());
            DataContext = _link;
        }

        private void AddCancel_CancelClicked(object sender, RoutedEventArgs e)
        {
            _link = new LinkViewModel(new DataStore.Domain.Link());
            DataContext = _link;

        }
    }

    public class LinkSavedEventArgs : EventArgs
    {
        readonly LinkViewModel _link;
        public LinkViewModel LinkVM { get
            {
                return _link;
            }
        }
        public Link Link { 
            get
            {
                return _link.Link;
            }
        }


        public LinkSavedEventArgs(LinkViewModel link)
        {
            _link = link;
        }
    }
}
